<template>
  <a-dropdown
    class="select-tiledt-list-control"
    :trigger="['click']"
    :getPopupContainer="GetPopupContainer"
    overlayClassName="select-tiledt-list-control-context-wrap"
  >
    <template #overlay>
      <div class="context">
        <rb-icon-button
          class="item"
          v-for="item in options"
          :key="item.value"
          :type="item.value"
          @click="onIconClick(item.value)"
        />
      </div>
    </template>
    <a-button>
      <rb-icon class="icon-it" :type="val" />
      <rb-icon class="btn-it" type="icon-luoshu-arrow-down" />
    </a-button>
  </a-dropdown>
</template>

<script lang="ts">
import { defineComponent, computed } from 'vue';
import { GetPopupContainer } from '@/global/util/preUtils';

export default defineComponent({
  name: 'SelecTiledtListControl',
  props: {
    value: {
      type: String,
      default: '',
    },
    controls: {
      type: Object,
      default: () => ({}),
    },
    controlKey: {
      type: String,
      default: () => '',
    },
    options: {
      type: Object,
      default: () => ({}),
    },
  },
  setup(props, context) {
    const val = computed({
      get: () => props.value,
      set: (val) =>
        context.emit('updateValue', val, props.controlKey, props.controls),
    });
    const onIconClick = (icon: string) => {
      val.value = icon;
    };

    return {
      GetPopupContainer,
      val,
      onIconClick,
    };
  },
});
</script>

<style lang="less" scoped>
.select-tiledt-list-control-context-wrap {
  .context {
    .flexRow(flex-start, center);
    flex-wrap: wrap;
    width: 240px;
    border: 1px solid @rb-border-color-base;
    border-radius: 2px;
    font-size: 31.6px;
    background-color: @rb-body-background;
    .item {
      padding: 4px 8px;
    }
  }
}
.select-tiledt-list-control {
  width: 100%;
  .flexRow(space-between, center);
  .icon-it {
    font-size: 24px;
  }
  .btn-it {
    font-size: 14px;
    color: @rb-disabled-color;
  }
}
</style>
